package ar.com.ctrln.view.dashboard.administracion.facturacion;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zkex.zul.Jasperreport;

import ar.com.ctrln.persistence.model.factura.Factura;
import ar.com.ctrln.view.ui.comportamientoVentana.AbstractMinimizarVentana;

@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class Reporte extends AbstractMinimizarVentana {

	private static final long serialVersionUID = -5597395787973974825L;

	@Wire
	private Jasperreport report;

	private Connection con;

	private Factura factura;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);

		factura = (Factura) this.getSelf().getParent().getAttribute("factura");
		imprimirFactura();

	}

	public void imprimirFactura() throws SQLException {
//
//		if (factura != null) {
//
//			SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
//			try {
//				Class.forName("com.mysql.jdbc.Driver");
//				con = DriverManager.getConnection(
//						"jdbc:mysql://localhost:3306/ctrln", "root", "root");
//			} catch (ClassNotFoundException e) {
//				e.printStackTrace();
//			}
//
//			String path = this.getPage().getDesktop().getWebApp()
//					.getRealPath("/resources/reportes/factura.jrxml");
//			String camino = path.replaceAll("\\\\", "/");
//
//			try {
//				Map param = new HashMap();
//				param.put("pIdFactura", (int) factura.getId());
//				
//				report.settyp
////
////				JasperReport jasperReport = JasperCompileManager
////						.compileReport(camino);
////				JasperPrint jasperPrint = JasperFillManager.fillReport(
////						jasperReport, param, con);
////				JasperViewer.viewReport(jasperPrint, false);
//				con.close();
//			} catch (JRException e) {
//				e.printStackTrace();
//			}

	}

}
